//
//  ViewController.m
//  STNewTools
//
//  Created by stoneobs on 17/1/11.
//  Copyright © 2017年 stoneobs. All rights reserved.
//

#import "ViewController.h"
#import "UIViewController+STNavigationTools.h"
#import "UIViewController+STPresent.h"
#import "STPickerViewController.h"
#import "STPopViewController.h"
#import "STWebViewController.h"
#import "STAdvertingScrollView.h"
#import "STRadioButton.h"
#import "STSegementButton.h"
#import "STImagePickerController.h"
#import "TZImagePickerController.h"
#import "AFNetworking.h"
#import <AVFoundation/AVFoundation.h>
#import "UIViewController+STNavigationTools.h"
#import "UIImage+STTools.h"
#import "STVideoPlayView.h"
#define SCREEN_HEIGHT  [UIScreen mainScreen].bounds.size.height
#define SCREEN_FRAME  [UIScreen mainScreen].bounds
#define SCREEN_WIDTH  [UIScreen mainScreen].bounds.size.width
@interface ViewController ()
@property(nonatomic,strong)STAdvertingScrollView            *adverView;
@property(nonatomic,strong)AVPlayer                         *player;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [UIColor grayColor];
    [self setRightItemWithTitle:@"right" titleColor:[UIColor orangeColor]];
    NSLog(@"沙盒\n------%@",NSHomeDirectory());
    NSArray * array = @[@"http://7xqhmn.media1.z0.glb.clouddn.com/femorning-20161106.mp4",
                        @"http://wvideo.spriteapp.cn/video/2016/0328/56f8ec01d9bfe_wpd.mp4",
                        @"http://baobab.wdjcdn.com/1456117847747a_x264.mp4",
                        @"http://baobab.wdjcdn.com/14525705791193.mp4",
                        @"http://baobab.wdjcdn.com/1456459181808howtoloseweight_x264.mp4",
                        @"http://baobab.wdjcdn.com/1455968234865481297704.mp4",
                        @"http://baobab.wdjcdn.com/1455782903700jy.mp4",
                        @"http://baobab.wdjcdn.com/14564977406580.mp4",
                        @"http://baobab.wdjcdn.com/1456316686552The.mp4",
                        @"http://baobab.wdjcdn.com/1456480115661mtl.mp4",
                        @"http://baobab.wdjcdn.com/1456665467509qingshu.mp4",
                        @"http://baobab.wdjcdn.com/1455614108256t(2).mp4",
                        @"http://baobab.wdjcdn.com/1456317490140jiyiyuetai_x264.mp4",
                        @"http://baobab.wdjcdn.com/1455888619273255747085_x264.mp4",
                        @"http://baobab.wdjcdn.com/1456734464766B(13).mp4",
                        @"http://baobab.wdjcdn.com/1456653443902B.mp4",
                        @"http://baobab.wdjcdn.com/1456231710844S(24).mp4"];
    STVideoPlayView * playView = [[STVideoPlayView alloc] initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 300) andVideoUrl:array[arc4random()%array.count - 1]];
    
    [self.tableView addSubview:playView];
    
}
-(void)viewWillAppear:(BOOL)animated
{

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor redColor] size:CGSizeMake(SCREEN_WIDTH, 64)] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:[UIColor blueColor] size:CGSizeMake(SCREEN_WIDTH, 1)]];
    [super viewWillAppear:animated];
    
}
- (void)viewWillDisappear:(BOOL)animated
{

    [super viewWillDisappear:animated];
}
- (BOOL)shouldAutorotate
{
    return NO;
}
- (UIStatusBarStyle)preferredStatusBarStyle {
    // 这里设置横竖屏不同颜色的statusbar
    // if (ZFPlayerShared.isLandscape) {
    //    return UIStatusBarStyleDefault;
    // }
    return UIStatusBarStyleLightContent;
}
#pragma mark ---tableview datasouse and delegate start
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 24;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell =[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self rightBarAction:nil];
    
    
}
#pragma mark ---tableview datasouse and delegate end
- (void)rightBarAction:(id)sender
{
   // [self imagePickerVCTest];
  //  [self downdTest];
    

    
    [self downdTest];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark --UIViewController Test
- (void)imagePickerVCTest{
    
    [self presentViewController:[[STImagePickerController alloc] initWithDefultRootVCHandle:^(NSArray<STPhotoModel *> *array) {
        
    }] animated:YES completion:^{
        
    }];
    

}
- (void)TZIpickerVCTest{
    [self presentViewController:[[TZImagePickerController alloc] initWithMaxImagesCount:100 delegate:self] animated:YES completion:^{
    
    }];
}
- (void)webViewVCTest{
    
    STWebViewController * vc = [[STWebViewController alloc] initWithUrl:@"https://www.baidu.com"];
    vc.progressBackgroundColor = [UIColor redColor];
    vc.progressTintColor = [UIColor orangeColor];
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark --View Test
- (void)maskViewTest{
    
}
- (void)maskLayerTest{
    
}
#pragma mark --NetWork Test
- (void)nomarlNetWorkTest{
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    [mgr.requestSerializer setTimeoutInterval:10];
    NSDictionary * dic = @{
                           @"id":@"45812",
                           @"type":@"0"};
    
    mgr.requestSerializer = [AFJSONRequestSerializer serializer];
    [mgr.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [mgr.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    [mgr.requestSerializer setValue:@"Fiil/1.7.2/(iPhone;10.2;Sacle/3.00)" forHTTPHeaderField:@"User-Agent"];
    [mgr.requestSerializer setValue:@"zh-Hans-CN;q=1" forHTTPHeaderField:@"Accept-Language"];
    [mgr.requestSerializer setValue:@"gzip, deflate" forHTTPHeaderField:@"Accept-Encoding"];
    
    [mgr.requestSerializer setValue:@"XMLHttpRequest" forHTTPHeaderField:@"X-Requested-With"];
    [mgr.requestSerializer setValue:@"03D11B58-9B26-4E34-9368-292FFF0E0EB6" forHTTPHeaderField:@"X-UUID"];
    [mgr.requestSerializer setValue:@"0" forHTTPHeaderField:@"X-Channel"];
    [mgr.requestSerializer setValue:@"com.suiyueyuele.suiyue.ios" forHTTPHeaderField:@"X-BundleId"];
    
    [mgr GET:@"https://api.suiyueyule.com/1.0.2/feed/new?lang=utf8&page=1" parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
    
}
- (void)downdTest{
    NSLog(@"%@",NSTemporaryDirectory());
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    [mgr.requestSerializer setTimeoutInterval:10];
    
    NSURLSessionDownloadTask *download = [mgr downloadTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://video-cdn.suiyueyule.com/o_1bdc2n9291tmcs4e1oj11k448gc.ts.mp4?auth_key=1492074663-0-0-d066552424ec3a9c2d720c86a9cea7bb"]] progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response) {
        NSFileManager *fileManager = [[NSFileManager alloc] init];
        NSString *pathDocuments = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *createDir = [NSString stringWithFormat:@"%@/echo_music", pathDocuments];
        
        // 判断文件夹是否存在，如果不存在，则创建
        if (![[NSFileManager defaultManager] fileExistsAtPath:createDir]) {
            [fileManager createDirectoryAtPath:createDir withIntermediateDirectories:YES attributes:nil error:nil];
        } else {
            NSLog(@"FileDir is exists.");
        }
        NSString *cachesPath = createDir;
        NSString *path = [cachesPath stringByAppendingPathComponent:response.suggestedFilename];
        NSLog(@"%@",path);
        return [NSURL fileURLWithPath:path];
    } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error) {
        
    }];
    [download resume];
}
@end
